package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Jxcg;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.JxcgMapper;
import com.gfxy.modules.items.service.IJxcgService;
import com.gfxy.modules.items.vo.JxcgMemberPage;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 教学成果奖
 * @Author: jeecg-boot
 * @Date:   2021-08-27
 * @Version: V1.0
 */
@Service
public class JxcgServiceImpl extends AbstractProjectServiceImpl<JxcgMapper, Jxcg> implements IJxcgService {

	protected int memberCellNum = 4;

	/**
	 * 次方法必须重写
	 * @param row
	 * @return
	 */
	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected Jxcg getOneProject(Row row) {
		String year = ExcelUtil.formatCell(row.getCell(0));
		String classessStr = ExcelUtil.formatCell(row.getCell(1));
		String award = ExcelUtil.formatCell(row.getCell(2));
		String projectName = ExcelUtil.formatCell(row.getCell(3));


		Jxcg jxcg = new Jxcg();
		jxcg.setDate(year);
		jxcg.setClassess(this.translateClassess(classessStr));
		jxcg.setAward(this.translateAward(award));
		jxcg.setProjectName(projectName);
		jxcg.setIsPass(0);

		//这个地方不要忘了-算总分
		jxcg.setTotalScore(this.getTotalScore(jxcg));
		return jxcg;
	}



	@Override
	protected void pass(String id, String isPass) {

	}



	@Override
	public Double getTotalScore(Jxcg jxcg) {
		double result = 0.0;
		int classess = jxcg.getClassess();
		int award = jxcg.getAward();
		if(classess == 1){
			if(award == 1){
				result = 1000;
			} else if(award == 2 ) {
				result = 500;
			} else if(award == 3 ) {
				result = 300;
			}
		} else if(classess == 2){
			if(award == 1){
				result = 200;
			} else if(award == 2 ) {
				result = 100;
			} else if(award == 3 ) {
				result = 50;
			}
		} else if(classess == 3){
			if(award == 1){
				result = 20;
			} else if(award == 2 ) {
				result = 15;
			} else if(award == 3 ) {
				result = 10;
			}
		}
		return result;
	}

	private int translateClassess(String name){
		if(name == null || name.equals("")){
			return 0;
		} else if(name.equals("国家级")){
			return 1;
		} else if(name.equals("省级")){
			return 2;
		} else if(name.equals("校级")){
			return 3;
		} else {
			return 0;
		}
	}
	private int translateAward(String award) {
		if(award == null || award.equals("")){
			return 0;
		} else if(award.equals("特等奖")){
			return 1;
		} else if(award.equals("一等奖")){
			return 2;
		} else if(award.equals("二等奖")){
			return 3;
		} else {
			return 0;
		}
	}

	@Override
	public Page<JxcgMemberPage> selectListPage(String date, int pageNum, int pageSize) {
		Page<JxcgMemberPage> page = new Page<>(pageNum,pageSize);
		return page.setRecords(this.baseMapper.selectJxcgMemberPageListByYear(date));
	}

	@Override
	public List<JxcgMemberPage> getJxcgMemberPageListByYear(String date) {
		return this.baseMapper.selectJxcgMemberPageListByYear(date);
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Jxcg jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(JxcgMemberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent awardTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(jxcg.getAward());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(JxcgMemberPage.class, "award", String.valueOf(jxcg.getAward())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}
}
